//
//  KAApplyResultVC.swift
//  kano
//
//  Created by Sophia on 2024/8/22.
//

import UIKit


enum KAApplyResult: Int {
    case success = 0
    case fail = 1
    case reviewing = 2
}

class KAApplyResultVC: KABaseVC {
    
    lazy var var_resultImg: UIImageView = {
        let var_resultImg = UIImageView(image: UIImage(named: "apply_success"))
        return var_resultImg
    }()
    
    public var symbolLabel: UILabel = {
        let label = UILabel()
        label.numberOfLines = 0
        label.font = UIFont.systemFont(ofSize: kscale(16), weight: .bold)
        label.textColor = .black
        label.text = ""
        return label
    }()
    
    lazy var var_homeBtn: UIButton = {
        let var_homeBtn = UIButton()
        var_homeBtn.setTitle("Home", for: .normal)
        var_homeBtn.setTitleColor(.white, for: .normal)
        var_homeBtn.titleLabel?.font = UIFont.systemFont(ofSize: kscale(17), weight: .bold)
        var_homeBtn.backgroundColor = .themeColor
        var_homeBtn.layer.cornerRadius = kscale(25)
        var_homeBtn.layer.masksToBounds = true
        var_homeBtn.addTarget(self, action: #selector(ka_var_homeBtnClick), for: .touchUpInside)
        return var_homeBtn
    }()
    @objc func ka_var_homeBtnClick() {
        navigationController?.popToRootViewController(animated: true)
    }
    
    override func customNavBackAction() {
        navigationController?.popToRootViewController(animated: true)
    }
    
    var result: KAApplyResult = .reviewing
    
    
    init(reviewResult: KAApplyResult) {
        result = reviewResult
        super.init(nibName: nil, bundle: nil)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension KAApplyResultVC {
    override func viewDidLoad() {
        super.viewDidLoad()
        ka_setUI()
    }
    
    func ka_setUI() {
        
        view.backgroundColor = .colorf2f2f5
        view.addSubview(var_resultImg)
        view.addSubview(var_homeBtn)
        view.addSubview(symbolLabel)
        var_resultImg.image = (result == .success || result == .reviewing) ? UIImage(named: "apply_success") : UIImage(named: "apply_fail")
        if result == .fail {
            let tipStr = """
Thank you for using our loan service. We regret to inform you that your credit application was not approved due to certain factors. The approval process takes into account various factors, such as credit history and financial status. If you have any questions, please feel free to contact our customer service team.

If you have concerns about your personal information, you can go to the account security page to deactivate your account, and we will delete all your data.

Thank you for your understanding. Wishing you all the best!
"""
            symbolLabel.text = tipStr
        } else if result == .success {
            symbolLabel.text = "Congratulations, your application has been approved."
        } else {
            symbolLabel.text = "Data review in progress, results are expected within 5 minutes. Please check back."
        }
        
        ka_showCustomerNavBar(type: .normal)
        var_navBar.var_titleLabel.text = "Profile Verification"
        
        var_resultImg.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: kscale(120), height: kscale(120)))
            make.top.equalTo(UIDevice.ka_fullNavHeight+kscale(32))
            make.centerX.equalTo(view)
        }
        symbolLabel.snp.makeConstraints { make in
            make.left.equalTo(view).offset(kscale(20))
            make.right.equalTo(view).offset(kscale(-20))
            make.top.equalTo(var_resultImg.snp.bottom).offset(kscale(18))
        }
        var_homeBtn.snp.makeConstraints { make in
            make.left.equalTo(view).offset(kscale(20))
            make.right.equalTo(view).offset(kscale(-20))
            make.top.equalTo(symbolLabel.snp.bottom).offset(kscale(40))
            make.height.equalTo(kscale(50))
        }
    }
}
